// pages/componet/view-start/view-star.js
//评论星星组件
var count = 0;
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        starts: {
            type: Array,
        },
        star_width:{
            type:String,
            value:'30rpx'
        },
        star_height:{
            type:String,
            value:'30rpx'
        },
        enable:{
            type:Boolean,
            value:false
        },
        offest:{
            type:Number,
            value: 30
        },
      currentScore:{
          type: Number,
            value:0
        }
    },
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached: function (options) { 
        // var currentShowScore = this.properties.current_score
        // this.setData({
        //     key:currentShowScore
        // })
    },
    moved: function () { },
    detached: function () { },
    /**
     * 组件的初始数据
     */
    data: {
        stars: [0, 1, 2, 3, 4],
        normalSrc: '../../../images/icons/icon_star_unselected.png',
        selectedSrc: '../../../images/icons/icon_star_selected.png',
        halfSrc: '../../../images/icons/icon_star_half_selected.png',
        key: 0,//评分
    },

    /**
     * 组件的方法列表
     */
    methods: {
        //点击左边,半颗星
        _selectLeft(e) {
            if (this.properties.enable===false){
                return
            }
            console.log('_selectLeft')
            var key = e.currentTarget.dataset.key
            if (this.data.key == 0.5 && e.currentTarget.dataset.key == 0.5) {
                //只有一颗星的时候,再次点击,变为0颗
                key = 0;
            }
            this._changeValue(key)
            console.log("count="+count)
        },
        //点击右边,整颗星
        _selectRight (e) {
            if (this.properties.enable === false) {
                return
            }
            console.log('_selectRight')
            var key = e.currentTarget.dataset.key
            this._changeValue(key)
            console.log("count=" + count)
        },
        _changeValue(_key){
            count = _key
            this.setData({
                key: _key
            })
            var args = { score: count}
            this.triggerEvent("changStatusListener", args,{});
        }
    }
})
